package com.xinxin.leetcode.problem680;

/**
 * @author ShiXinXin
 * @date 2020-02-22 22:39
 */
public class Solution {
    private boolean sign = true;

    private boolean validPalindrome(String str, int start, int end) {
        if (start >= end) {
            return true;
        }
        while (start < end) {
            if (str.charAt(start) == str.charAt(end)) {
                start++;
                end--;
            }else {
                break;
            }
        }
        if (start >= end) {
            return true;
        }
        if (sign) {
            sign = false;
            return validPalindrome(str, start + 1, end) || validPalindrome(str, start, end - 1);
        } else {
            return false;
        }
    }

    public boolean validPalindrome(String s) {
        return validPalindrome(s, 0, s.length() - 1);
    }

    public static void main(String[] args) {
        System.out.println(new Solution().validPalindrome("ececabbacec"));
    }
}
